package com.powernode.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.Prod;
import com.powernode.domain.ProdComm;
import com.powernode.service.ProdCommService;
import com.powernode.vo.ProdCommData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/prod/prodComm")
@RestController
@Api(tags = "评论管理接口")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;

    @GetMapping("/page")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    @ApiOperation("评论管理")
    public ResponseEntity<Page<ProdComm>> getProdCommPage(Page<ProdComm> page, ProdComm prodComm) {
        page = prodCommService.getProdCommPage(page, prodComm);
        return ResponseEntity.ok(page);
    }

    /**
     * 小程序获取商品评论数据
     *
     * @param prodId
     * @return
     */
    @GetMapping("/prodComm/prodCommData")
    @ApiOperation(value = "商品评论")
    public ResponseEntity<ProdCommData> getProdCommData(Long prodId) {
        //获取到商品评论条数
        ProdCommData prodCommData = prodCommService.getProdCommData(prodId);
        return ResponseEntity.ok(prodCommData);
    }

    /**
     * 小程序获取商品评论数量
     * @return
     */
    @GetMapping("/prodComm/prodCommPageByProd")
    @ApiOperation(value = "商品评论")
    public ResponseEntity<Page<ProdComm>> getProdCommPageByProd(Page<ProdComm> page,Long prodId,Integer evaluate) {
        page=prodCommService.getProdCommPageByProd(page,prodId,evaluate);
        return ResponseEntity.ok(page);
    }
}
